-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added [Feature]: a toString() method for enumerated values in Java #103
base: main
Are you sure you want to change the base?
Added [Feature]: a toString() method for enumerated values in Java #103
Conversation
Signed-off-by: Subhajit Ghosh <[email protected]>
Signed-off-by: Subhajit Ghosh <[email protected]>
Signed-off-by: Subhajit Ghosh <[email protected]>
hey @mttrbrts @sanketshevkar can you please review and give some feedback |
Signed-off-by: Subhajit Ghosh <[email protected]>
@@ -1196,6 +1208,10 @@ import com.fasterxml.jackson.annotation.*; | |||
public enum LaptopMake { | |||
Apple, | |||
Microsoft, | |||
@Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if enums in java store functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it does, because I have created one java program where I declared a enum and inside it defined the toString function and it worked totally final without any issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thanks for clarification. I'm not much proficient in Java. @mttrbrts can you please review this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a sample code snippet
public class Main{
public enum State {
MA,
NY,
CO,
// Override the toString() method for the entire enum type
@Override
public String toString() {
return name();
}
}
public static void main(String[] args) {
// Using the enum constants
State state1 = State.MA;
State state2 = State.NY;
String ma = state1.toString(); // This will call the overridden toString() method
// Printing the enum constants
System.out.println("State 1: " + ma);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sanketshevkar Have one question, How can I pass extra parameters like parameters.filewriter
as show in the code.. I mean to say can we pass other parameter like this parameters.x
?
concerto-codegen/lib/codegen/fromcto/java/javavisitor.js
Lines 142 to 146 in 7c14d70
parameters.fileWriter.writeLine(0, 'public enum ' + enumDeclaration.getName() + ' {' ); | |
enumDeclaration.getOwnProperties().forEach((property) => { | |
property.accept(this, parameters); | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you can. it is an options object on the visitor. (answered by @dselman on the Tech WG call)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you can. it is an options object on the visitor. (answered by @dselman on the Tech WG call)
Okay ... I am assuming is that something like this parameters.options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
18522a9
to
7c14d70
Compare
Closes accordproject/concerto#100
Changes
Author Checklist
--signoff
option of git commit.main
fromfork:branchname